package com.jinke.api.modules.third.shipber.model.response;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jinke.api.common.api.CommonResult;
import lombok.Data;

import java.util.List;

@Data
public class GetPriceResponse {

    private String message;
    private Boolean success = true;
    private DataT data;


    @Data
    public static class DataT {
        private List<Rate> rates;

        // Getters and setters
    }

    @Data
    public static class Rate {
        private Charge charge;

        @JsonProperty("charge_detail")
        private ChargeDetail chargeDetail;

        @JsonProperty("total_billable_weight")
        private BillableWeight totalBillableWeight;

        private String carrier;

        @JsonProperty("service_code")
        private String serviceCode;

        @JsonProperty("service_name")
        private String serviceName;

        @JsonProperty("carrier_service")
        private String carrierService;

        @JsonProperty("account_alias")
        private String accountAlias;

        @JsonProperty("rate_id")
        private String rateId;

        // Getters and setters
    }

    @Data
    public static class Charge {
        private String code;
        private Double value;

        // Getters and setters
    }

    @Data
    public static class ChargeDetail {
        @JsonProperty("rate_quote")
        private double rateQuote;

        @JsonProperty("sub_charge")
        private List<SubCharge> subCharges;

        // Getters and setters
    }

    @Data
    public static class SubCharge {
        private String type;
        private String name;
        private double money;

        // Getters and setters
    }

    @Data
    public static class BillableWeight {
        private double value;
        private String code;

        // Getters and setters
    }


    public boolean isSuccess() {
        boolean result = true;
        // 判断是否成功
        if (StringUtils.isNotBlank(message)) {
            result = false;
        }
        return result;
    }

    public CommonResult toCommonResult() {
        // 判断是否成功
        CommonResult commonResult = CommonResult.success();
        if (StringUtils.isNotBlank(message)) {
            success = false;
            commonResult = CommonResult.failed(message);
        }

        return commonResult;
    }

}
